package ch.hoth.java.joocal;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.google.gdata.data.DateTime;

public class DateUtil {

	private static Calendar calendar = new GregorianCalendar();
	private static SimpleDateFormat formatter = new SimpleDateFormat();
	
	
	public static Date getNextDay(Date date){
		return getDay(date, +1);
		
	}
	
	public static Date getPreviousDay(Date date){
		return getDay(date, -1);
	}
	
	public static String format(String pattern, DateTime dateTime){
		Date date = new Date(dateTime.getValue());
		return format(pattern, date);
	}
	
	public static String format(String pattern, Date date){
		
		String value = null;
		if (date != null){
			formatter.applyPattern(pattern);
			value = formatter.format(date);			
		}
		else{
			value = "???";
		}
		return value;
	}
	
	private static Date getDay(Date oldDate, int days){
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(oldDate);
		calendar.add(GregorianCalendar.DAY_OF_MONTH, days);
		return (Date) calendar.getTime().clone();
	}
	
}
